package com.cskaoyan.controller;

import com.cskaoyan.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * Controller组件中包含Handler方法
 * @author stone
 * @date 2021/11/22 14:28
 */
@Controller
public class HelloController {

    //HandlerMethod要处理请求
    @RequestMapping("/hello1")
    public ModelAndView hello1(){
        //视图和模型数据
        ModelAndView modelAndView = new ModelAndView();
        //View
        modelAndView.setViewName("/hello.jsp");
        //Model
        modelAndView.addObject("songge", "song brother");
        return modelAndView;
    }

    @ResponseBody
    @RequestMapping("/hello2")
    public String hello2() {
        return "hello world";
    }

    @ResponseBody
    @RequestMapping("hello3")
    public User hello3() {
        User user = new User();
        user.setUsername("松哥");
        user.setPassword("牛皮");
        return user; //user 👉 Json String（jackson）
    }

    //@RequestMapping("register")

    //@RequestMapping("login")
}
